package com.ourteam.product.requirement.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.requirement.dao.IProductIssueDAO;
import com.ourteam.product.requirement.dao.ProductIssueDAOQueryBean;
import com.ourteam.product.requirement.domain.ProductIssueBean;

public class ProductIssueSearchModel extends AbstractSearchModel<ProductIssueDAOQueryBean> {

	private String issueTitle;

	private String status;

	private String issueType;

	private Long productVersionId;

	private Long productDefineId;

	private Long creatorId;

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductIssueBean.getMappedDAOField(aProperty);
	}

	public String getIssueTitle() {
		return issueTitle;
	}

	public void setIssueTitle(String issueTitle) {
		this.issueTitle = issueTitle;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Long getProductVersionId() {
		return productVersionId;
	}

	public void setProductVersionId(Long productVersionId) {
		this.productVersionId = productVersionId;
	}

	public Long getProductDefineId() {
		return productDefineId;
	}

	public void setProductDefineId(Long productDefineId) {
		this.productDefineId = productDefineId;
	}

	public String getIssueType() {
		return issueType;
	}

	public void setIssueType(String issueType) {
		this.issueType = issueType;
	}

	public Long getCreatorId() {
		return creatorId;
	}

	public void setCreatorId(Long creatorId) {
		this.creatorId = creatorId;
	}

	@Override
	protected void doBuildQueryBean(ProductIssueDAOQueryBean queryBean) throws Exception {

		ProductIssueDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.productVersionId != null && this.productVersionId.longValue() != 0) {
			criteria.andProductVersionIdEqualTo(productVersionId);
		}

		if (this.productDefineId != null && this.productDefineId.longValue() != 0) {
			criteria.andProductDefineIdEqualTo(productDefineId);
		}

		if (StringUtils.isNotEmpty(issueType)) {
			criteria.andIssueTypeEqualTo(issueType);
		}

		if (StringUtils.isNotEmpty(issueTitle)) {
			criteria.andIssueTitleLike(issueTitle);
		}

		if (StringUtils.isNotEmpty(status)) {
			criteria.andStatusEqualTo(status);
		}
		
		if (this.creatorId != null && this.creatorId.longValue() != 0) {
			criteria.andCreatorIdEqualTo(creatorId);
		}
		
	}

}
